if(!coos.form)coos.form = function(){};

coos.form.post = function(){};

coos.cstock = function(){};

coos.changeSelect = function()
{
	var form = coos.$id('orderStringForm');
	var orgCode = coos.$id("orgCode_select").value;
	var orderString = coos.$id("orderString").value;
	var action = coos.url.replaceAttribe("orgCode",orgCode,form.action);
	action = coos.url.replaceAttribe("orderString",orderString,action);
	form.action = action;
	form.removeChild(coos.$id('orderString'));
	form.submit();
	return false;
};

coos.cstock.changeOrgCode = function(selectId,type,aId)
{
	var select = coos.$id(selectId);
	var a = coos.$id(aId);
	var orderString = "totalYieldRatio,desc";
	if(coos.$id("orderString"))
	{
		orderString = coos.$id("orderString").value;
	}
	
	var url = coos.url.replaceAttribe("orgCode",select.value,a.href);
	url = coos.url.replaceAttribe("orderString",orderString,url);
	a.href = url;
	return false;
};

coos.cstock.changeFundId = function(url,inputId,aId)
{
	var input = coos.$id(inputId);
	var a = coos.$id(aId);
	a.href = coos.url.replaceAttribe("fundId",input.value,url);
	return false;
};

function init_menu(el,ifr)
{
	var lis = coos.$tag("li",el);
	var len = lis.length;
	for(var i=0; i < len; i++)
	{
		lis[i].onclick = function(event)
		{
			var e = coos.event.format(coos.event(event));
			var el = e.target;
			//如果没有action属性则默认为""
			var action = el.getAttribute("action") || "";
			//先设置选中，避免选中状态出来太晚
			el.className = "menubox_select";
			for(var i=0; i < len; i++)
			{
				if(el == lis[i])continue;
				lis[i].className = "";
			}
			coos.$obj(ifr).src = action;
			
		};
	}
};

coos.cstock.stockSelected = function(geturl,successUrl)
{
	coos.ajax.get(geturl,coos.cstock.stockSelected.callback,{"successUrl":successUrl});
	return false;
};

coos.cstock.stockSelected.callback = function(responseText,successUrl)
{
	var rs = responseText.toJson();
	if(rs.state == "error")
	{
		alert("操作失败：" + rs.message);
	}
	else if(rs.state == "success")
	{
		//parent.coos.url.location(successUrl);
		alert("自选股添加成功！");
	}
	else
	{
		alert(rs.message);
	}
};

coos.cstock.removeStockSelected = function(geturl)
{
	coos.ajax.get(geturl,coos.cstock.removeStockSelected.callback);
	return false;
};

coos.cstock.removeStockSelected.callback = function(responseText)
{
	var rs = responseText.toJson();
	
	if(rs.state == "error")
	{
		alert("操作失败：" + rs.message);
	}
	else
	{
		coos.url.location();
	}
};

